package com.vogue.supplymall.order.common;

import java.math.BigDecimal;
import java.util.Map;
import java.util.function.BiFunction;

/**
 * The type Calc order item utils.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-01-25
 */
public class CalcOrderItemUtils {

    public static void calcOrder(Map<String, Object> product) {
        BiFunction<String, String, BigDecimal> calcItemprice = (v1, v2) -> new BigDecimal(v1).multiply(new BigDecimal(v2));
        if (null != product.get("private_price")) {
            product.put("itemprice", calcItemprice.apply(
                    product.get("private_price").toString(),
                    product.get("itemquantity").toString()
            ));
        } else {
            product.put("itemprice", calcItemprice.apply(
                    product.get("public_price").toString(),
                    product.get("itemquantity").toString()
            ));
        }
    }
}
